package com.cskaoyan.dbutils.impl;

import com.cskaoyan.dbutils.Cskaoyan;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 创建日期: 2022/06/05 17:39
 *
 * @author ciggar
 */
public class MyResultSetHandler implements ResultSetHandler<List<Cskaoyan>> {
    @Override
    public List<Cskaoyan> handle(ResultSet resultSet) throws SQLException {

        ArrayList<Cskaoyan> list = new ArrayList<>();

        while (resultSet.next()) {

            Cskaoyan cskaoyan = new Cskaoyan();

            int id = resultSet.getInt("id");
            String nickname = resultSet.getString("nickname");
            String teacherName = resultSet.getString("teacher_name");
            int money = resultSet.getInt("money");

            cskaoyan.setId(id);
            cskaoyan.setNickname(nickname);
            cskaoyan.setTeacherName(teacherName);
            cskaoyan.setMoney(money);

            list.add(cskaoyan);

        }
        return list;
    }
}
